package club.banyuan.demo.demo7;

import java.lang.reflect.Array;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;

/**
 * @author edz
 * @version 1.0
 * @date 2020/12/22 下午7:43
 */
public class ReflectDemo3 {
    public static void main(String[] args) throws NoSuchMethodException, InvocationTargetException, IllegalAccessException {
        ArrayList<Integer> arr = new ArrayList<>();
        //在Integer数组里面加字符串
        Class<? extends ArrayList> c = arr.getClass();
        //字节码文件c中的add方法的参数是object的，所以可以添加字符串
        Method add = c.getMethod("add", Object.class);

        add.invoke(arr,"hello");
        System.out.println(arr);


    }
}
